package com.arqui.admmon_module.server.handlers;

import java.rmi.RemoteException;
import java.util.ArrayList;
import java.util.List;
import javax.xml.rpc.ServiceException;
import com.gwtplatform.dispatch.server.actionhandler.ActionHandler;
import com.arqui.admmon_module.client.action.RealTimeServices;
import com.arqui.admmon_module.client.action.RealTimeServicesResult;
import com.arqui.admmon_module.server.services.ExternalEventsService;
import com.arqui.admmon_module.server.webservices.eventsmonitor.NonexistentEntityException;
import com.arqui.admmon_module.server.webservices.eventsmonitor.UnknownHostException;
import com.arqui.admmon_module.shared.ServicesEntity;
import com.google.inject.Inject;
import com.gwtplatform.dispatch.server.ExecutionContext;
import com.gwtplatform.dispatch.shared.ActionException;

public class RealTimeServicesActionHandler implements
		ActionHandler<RealTimeServices, RealTimeServicesResult> {

	@Inject
	public RealTimeServicesActionHandler() {
	}

	@Override
	public RealTimeServicesResult execute(RealTimeServices action,
			ExecutionContext context) throws ActionException {
		ExternalEventsService service = new ExternalEventsService();
		List<ServicesEntity> result= new ArrayList<ServicesEntity>();
		try {
			result = service.getExternaServicesRealTime();
		} catch (UnknownHostException e) {
			e.printStackTrace();
		} catch (NonexistentEntityException e) {
			e.printStackTrace();
		} catch (RemoteException e) {
			e.printStackTrace();
		} catch (ServiceException e) {
			e.printStackTrace();
		} catch (Exception e) {
			e.printStackTrace();
		}
;		return new RealTimeServicesResult(result);
	}

	@Override
	public void undo(RealTimeServices action, RealTimeServicesResult result,
			ExecutionContext context) throws ActionException {
	}

	@Override
	public Class<RealTimeServices> getActionType() {
		return RealTimeServices.class;
	}
}
